package com.xxx.test;

import com.xxx.DAO.commentDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addComment")
public class addComment extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userName= (String) request.getSession().getAttribute("userName");
        String uIden= (String) request.getSession().getAttribute("iden");
        String comment = new String(request.getParameter("comment").getBytes("UTF-8"), "UTF-8");
        commentDao dao = new commentDao();
        int i=dao.add(userName,comment,uIden);
        request.getRequestDispatcher("showComment").forward(request,response);
        System.out.println(i);

    }
}

